/**
 * Settle模块 - 商户管理API
 * @description 商户管理相关的API接口定义
 * @author AI Assistant
 * @since 1.0.0
 */

import request from '@/config/axios'
import type {
  MerchantVO,
  MerchantCreateReqVO,
  MerchantUpdateReqVO,
  MerchantPageReqVO,
  PageResult
} from './types'

/**
 * 获取商户分页列表
 * @param params 分页查询参数
 * @returns 商户分页数据
 */
export const getMerchantPageApi = (params: MerchantPageReqVO): Promise<PageResult<MerchantVO>> => {
  return request.get({ url: '/settle/merchant/page', params })
}

/**
 * 获取商户详情
 * @param id 商户ID
 * @returns 商户详情
 */
export const getMerchantApi = (id: number): Promise<MerchantVO> => {
  return request.get({ url: `/settle/merchant/get?id=${id}` })
}

/**
 * 创建商户
 * @param data 商户创建数据
 * @returns 创建结果
 */
export const createMerchantApi = (data: MerchantCreateReqVO): Promise<number> => {
  return request.post({ url: '/settle/merchant/create', data })
}

/**
 * 更新商户
 * @param data 商户更新数据
 * @returns 更新结果
 */
export const updateMerchantApi = (data: MerchantUpdateReqVO): Promise<boolean> => {
  return request.put({ url: '/settle/merchant/update', data })
}

/**
 * 删除商户
 * @param id 商户ID
 * @returns 删除结果
 */
export const deleteMerchantApi = (id: number): Promise<boolean> => {
  return request.delete({ url: `/settle/merchant/delete?id=${id}` })
}

/**
 * 审核商户
 * @param id 商户ID
 * @param status 审核状态: 1-审核通过 2-审核拒绝
 * @param remark 审核备注
 * @returns 审核结果
 */
export const auditMerchantApi = (id: number, status: number, remark?: string): Promise<boolean> => {
  return request.put({
    url: '/settle/merchant/audit',
    data: { id, status, remark }
  })
}

/**
 * 冻结商户
 * @param id 商户ID
 * @param remark 冻结原因
 * @returns 冻结结果
 */
export const freezeMerchantApi = (id: number, remark?: string): Promise<boolean> => {
  return request.put({
    url: '/settle/merchant/freeze',
    data: { id, remark }
  })
}

/**
 * 解冻商户
 * @param id 商户ID
 * @param remark 解冻原因
 * @returns 解冻结果
 */
export const unfreezeMerchantApi = (id: number, remark?: string): Promise<boolean> => {
  return request.put({
    url: '/settle/merchant/unfreeze',
    data: { id, remark }
  })
}

/**
 * 获取商户列表(不分页)
 * @param status 商户状态(可选)
 * @returns 商户列表
 */
export const getMerchantListApi = (status?: number): Promise<MerchantVO[]> => {
  const params = status !== undefined ? { status } : {}
  return request.get({ url: '/settle/merchant/list', params })
}

/**
 * 导出商户数据
 * @param params 查询参数
 * @returns 导出文件
 */
export const exportMerchantApi = (params: MerchantPageReqVO): Promise<void> => {
  return request.download({
    url: '/settle/merchant/export',
    params
  })
}
